import myRequest from '../request.js'
import dicts from '@/config/dicts.js'

// 获取轮播图
export const getBanner = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + '/common/mall/banner', 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 快速导航
export const getFloor = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + '/common/mall/floor/tree', 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取活动楼层数据
export const activityData = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + val.path, 'get', val.params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//底部活动
export const getBottomActivity = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + '/common/mall/ceiling', 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//底部活动数据
export const getBottomActivityData = (val, params) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + val, 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 搜索热词
export const hotWords = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/goods/goods/hot-words', 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取厂家规格筛选参数
export const getManufactor = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/goods/goods/sku/keyword/condition', 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 搜索
export const getSearchList = (params) => {
	return new Promise((resolve, reject) => {
		// myRequest(dicts.buyer + '/purchaser/goods/goods/sku/keyword', 'get', params).then(res => {
		myRequest(dicts.buyer + '/purchaser/goods/goods/sku/search', 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 商品详情  
export const getGoodsInfo = (id) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/goods/goods/sku/' + id, 'get', {
			structuredRule: true
		}).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 查询是否已收藏
export const hasCollection = (type, id) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/member/collection/isCollection/' + type + '/' + id, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 收藏
export const collection = (type, id) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/member/collection/add/${type}/${id}`, 'post').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 取消收藏
export const cancelCollection = (type, id) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/member/collection/delete/${type}/${id}`, 'delete').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取购物车数量
export const getCartNUm = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/trade/carts/count', 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 加入购物车 
export const addToCart = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/trade/carts', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取优惠券楼层 banner图
export const getCouponBanner = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + val, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取 楼层 dedicated discount  banner
export const getDedicatedBanner = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + val, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取 楼层 dedicated discount  数据
export const getDedicatedData = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + val, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// IM 客服
export const customerService = (code) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + '/common/common/cust/care', 'get', {
			code: code
		}).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 首页广告列表
export const advertisementList = (params) => {
	return new Promise((resolve, reject) => {
		let clientType
		// #ifdef MP-WEIXIN
		clientType = 'WECHAT_MP'
		// #endif
		// #ifdef MP-TOUTIAO
		clientType = 'DOUYIN_MP'
		// #endif
		// #ifndef MP
		clientType = 'APP'
		// #endif
		// ?env=dev
		myRequest(dicts.essential + `/common/setting/ads/${clientType}/HOME`, 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 首页广告
export const advertisement = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + '/common/setting/ads/WECHAT_MP/HOME/current', 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 自动补全
export const setComplete = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/goods/goods/es/suggestion', 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 自动更新   
export const automaticUpdate = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/other/appVersion/' + uni.getSystemInfoSync().osName, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 未知链接请求
export const unknownRequest = (path, type) => {
	return new Promise((resolve, reject) => {
		myRequest(path, type).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}